package com.oms.module.merchant.controller;

import com.oms.common.ResponseDTO;
import com.oms.module.merchant.constant.MerChantResponseCodeConstant;
import com.oms.module.merchant.domain.entity.ShopEntity;
import com.oms.module.merchant.domain.vo.AddShopVO;
import com.oms.module.merchant.service.ShopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @Author zhanghailong QQ38592077
 * @Description TODO
 * @Date 2020/7/13 16:51
 */
@RestController
@RequestMapping("/user")
@Api(description = "商家店铺管理")
public class ShopManagerController {

    @Resource
    ShopService shopService;

    @PostMapping("/shop")
    @ApiOperation("添加店铺")
    public ResponseDTO addShop(@RequestBody @Valid AddShopVO addShopVO){
        ShopEntity shopEntity = new ShopEntity();
        BeanUtils.copyProperties(addShopVO,shopEntity);
        boolean save = shopService.save(shopEntity);
        if (save){
            return ResponseDTO.succMsg("新增成功！");
        }
        return ResponseDTO.wrap(MerChantResponseCodeConstant.ADD_SHOP_ERROR);
    }

    @GetMapping("/shop")
    @ApiOperation("获取店铺列表")
    public ResponseDTO getList(Long userId){
        List<ShopEntity> list = shopService.lambdaQuery().eq(ShopEntity::getUserId, userId).list();
        return ResponseDTO.succData(list);
    }
}
